// pages/mine/shop/card/setting.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    id:'',
    nav: [
      { title: '等级设置', icon: 'vip', url: 'level', color_id: 7 },
      { title: '服务商品', icon: 'log', url: 'good', color_id: 7 },
      { title: '套餐按次设置', icon: 'gouwudai', url: 'meal', color_id: 5 },
      // { title: '核销', icon: 'qrcode', url: './yan/list', color_id: 2 },
      // { title: '充值套餐设置', icon: 'gif', url: 'rechargemeal', color_id: 4 },

      { title: '充值优惠设置', icon: 'gif', url: 'recharge', color_id: 7 },
      { title: '会员简介特权', icon: 'log', url: 'rights', color_id: 6 },
      { title: '推荐奖设置', icon: 'edit', url: 'recommend', color_id: 5 },
      { title: '会员专属优惠券', icon: 'video', url: 'coupon', color_id: 7 },
      { title: '积分', icon: 'doc', url: 'credit', color_id: 8 },
      { title: '关联其他商家优惠', icon: 'bbs', url: 'linkshop', color_id: 9 },
      
      { title: '会员卡设置', icon: 'edit', url: 'add', color_id: 3 },
      
    ],
  
    showShopJoinAgreement: 0
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      card_id: options.id
    });
    
  },
  // 获取 会员卡的相关信息
  getCard: function () {
    let that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/Card/shopCard/openid/' + app.globalData.openid+'/card_id/'+that.data.card_id, function (res) {
      that.setData({
        card: res.data
      })
      wx.hideLoading();
    });
  },

  openshopcard: function () {
    var that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/openShopcard/shop_id/' + that.data.shop_id, function (res) {
      wx.showToast({
        title: res.data.err_msg,
      })
      that.onLoad();
    })

  },
  jump: function (options) {
    let that = this;
    var url = options.currentTarget.dataset.url;
    var id = options.currentTarget.dataset.id;
    var wid = this.data.info.wid;
    if (url == 'add'){
      url = url + "?type=edit&id=" + that.data.card_id ;
    }else{
      url = url + "?id=" + that.data.card_id + '&&openid=' + app.globalData.openid;
    }
    

    
    wx.navigateTo({
      url: url,
    })
  },
  jump_vip: function (options) {
    var t = this
    wx.showModal({
      title: '提示',
      cancelText: '关闭',
      cancelColor: '#323232',
      confirmText: '前往',
      confirmColor: '#ec5e2a',
      content: '此功能为付费功能，是否前往查看？',
      success: function (o) {
        if (o.confirm) {
          var url = options.currentTarget.dataset.url;
          var id = options.currentTarget.dataset.id;
          var wid = t.data.info.wid;
          // wx.showToast({
          //   icon:'none',
          //   title: '开发中，敬请期待！',
          // })
          wx.navigateTo({
            url: '/pages/mine/shop/vip',
          })
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;

    wx.showLoading({
      title: '加载中…',
    })
    app.ihttpGet('https://www.58zltc.com/api.php/ShopAdmin/getInfo/openid/' + app.globalData.openid, function (res) {
      app.ihttpGet('https://www.58zltc.com/api.php/ShopAdmin/verJoinEndTime/shop_id/' + res.data.shop_id, function (resq) {
        that.setData({
          verJoinEndTime: resq.data
        })
      })

      that.setData({
        info: res.data,
        shop_id: res.data.shop_id,
      })

      wx.hideLoading();
    })
    this.getCard();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  hiden_agreement: function () {
    var that = this
    this.setData({
      showShopJoinAgreement: 0
    })
    wx.navigateTo({
      url: './card/joincard?shop_id=' + that.data.shop_id,
    })
  }
})